﻿using AutoMapper;
using B.S.Warehouse.Domain;
using B.S.Warehouse.ErrorCord;
using B.S.Warehouse.Read.Api.Application.Command.OutboundCommand;
using MediatR;
using SqlSugar;

namespace B.S.Warehouse.Read.Api.Application.Handelr.OutboundHandler
{
    public class FTOutboundHandler : IRequestHandler<FTOutboundCommand, ApiResult<List<Outbounds>>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;
        public FTOutboundHandler(ISqlSugarClient db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }

        public async Task<ApiResult<List<Outbounds>>> Handle(FTOutboundCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Outbounds>> result = new ApiResult<List<Outbounds>>();
            result.Code = ApiEnum.显示成功;
            result.MAG = ApiEnum.显示成功.ToString();

            var list = await db.Queryable<Outbounds>().Where(x => x.IsDel == false && x.OutboundId == request.OutboundId).ToListAsync();
            result.data = list;
            return await Task.FromResult(result);
        }
    }
}
